import http from '@/utils/http'

/**
 * @description: 验证码借口
 * @author: Daniel
 */
export async function captchaImage() {
  try {
    let url = '/captchaImage'
    const data = await http.get(url)
    if (data?.code) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 登录接口
 * @author: Daniel
 */
export async function login(ages = {}) {
  try {
    let url = '/login'
    const params = {
      username: '',
      password: '',
      code: '1',
      uuid: '',
      ...ages,
    }
    const data = await http.post(url, params)
    console.log('res123', data)

    if (data?.code === 200) {
      return { ...data, type: true }
    }
    return { ...data, type: false }
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 用户管理列表
 * @author: Daniel
 */
export async function list(ages = {}) {
  try {
    let url = '/system/user/list'
    const params = {
      pageNum: 1,
      pageSize: 5,
      deptId: '',
      ...ages,
    }
    const data = await http.get(url, params)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}
/**
 * @description: 用户列表新增
 * @author: Daniel
 */
export async function user(ages = {}) {
  try {
    let url = '/system/user'
    const params = {
      ...ages,
    }
    const data = await http.post(url, params)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 用户列表编辑
 * @author: Daniel
 */
export async function userEdit(ages = {}) {
  try {
    let url = '/system/user'
    const params = {
      ...ages,
    }
    const data = await http.put(url, params)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 用户列表删除
 * @author: Daniel
 */
export async function userDelete(id) {
  try {
    let url = '/system/user/' + id

    const data = await http.delete(url)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 组织接口
 * @author: Daniel
 */
export async function treeselect(ages = {}) {
  try {
    let url = '/system/dept/treeselect'

    const data = await http.get(url)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 性别接口
 * @author: Daniel
 */
export async function userSex(ages = {}) {
  try {
    let url = '/system/dict/data/type/sys_user_sex'

    const data = await http.get(url)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 状态接口
 * @author: Daniel
 */
export async function userDisable(ages = {}) {
  try {
    let url = '/system/dict/data/type/sys_normal_disable'

    const data = await http.get(url)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}

/**
 * @description: 角色接口
 * @author: Daniel
 */
export async function userRoles(ages = {}) {
  try {
    let url = '/system/user/'

    const data = await http.get(url)

    if (data?.code === 200) {
      return data
    }
    return false
  } catch (error) {
    console.log('error', error)
  }
}
